﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#if !WINDOWS_PHONE


#endif

namespace DARE
{
    [AttrTypeDependentSerializable(typeof(DARE.Save.DataStructures.CTriangleMeshModelData))]
    public class CTriangleMeshModel : CBasicModel
    {

    #region fields

    #endregion

    #region properties

    #endregion

    #region ctor

        public CTriangleMeshModel(VertexPositionNormalTexture[] vertices, short[] indices)
            : base()
        {
            Initialize(vertices, indices);
        }

        public CTriangleMeshModel(string name, VertexPositionNormalTexture[] vertices, short[] indices)
            : base(name)
        {
            Initialize(vertices, indices);
        }

        private void Initialize(VertexPositionNormalTexture[] vertices, short[] indices)
        {
            m_primitiveType = PrimitiveType.TriangleList;
            //m_cullMode = CullMode.None;
            CullMode = CullMode.None;
            Setup(vertices, indices);
            CreateVertexBuffer();
            CreateIndexBuffer();
        }

    #endregion

    #region methods

        private void Setup(VertexPositionNormalTexture[] vertices, short[] indices)
        {
#if WINDOWS_PHONE
            m_vertices = new VertexPositionNormalTexture[vertices.Length];
            for (int i = 0; i < vertices.Length; ++i)
                m_vertices[i] = new VertexPositionNormalTexture(
                    vertices[i].Position, vertices[i].Normal, vertices[i].TextureCoordinate);
#else
            m_vertices = new VertexPositionNormalTextureTangentBinormal[vertices.Length];
            for (int i = 0; i < vertices.Length; ++i)
                m_vertices[i] = new VertexPositionNormalTextureTangentBinormal(
                    vertices[i].Position, vertices[i].Normal, vertices[i].TextureCoordinate);
#endif

            m_indices = indices;
        }

    #endregion

    }
}
